<?php

declare(strict_types=1);

namespace App\CustHub\Mapper;

use App\CustHub\Model\ChRoomMemberToKick;
use Hyperf\Cache\Annotation\Cacheable;
use Hyperf\Config\Annotation\Value;
use Hyperf\Database\Model\Builder;
use Hyperf\Database\Model\Model;
use Mine\Abstracts\AbstractMapper;

class ChRoomMemberToKickMapper extends AbstractMapper
{

    #[Value('cache.default.prefix')]
    protected string $prefix;


    public function assignModel()
    {
        $this->model = ChRoomMemberToKick::class;
    }

    /**
     * 根据id获取数据
     * @param int $id
     * @return ChRoomMemberToKick|Model|string|Builder|null
     */
    public function findById(int $id): ChRoomMemberToKick|\Hyperf\Database\Model\Model|string|Builder|null
    {
        return $this->model::query()->where('id',$id)->first();
    }

    public function getPendingKickInfo(string $fromRoomWxid,int $robotId,string $userId): ChRoomMemberToKick|\Hyperf\Database\Model\Model|string|Builder|null
    {
        return $this->model::query()
            ->where('from_room_id',$fromRoomWxid)
            ->where('robot_id',$robotId)
            ->where('user_id',$userId)
            ->where('status',0)
            ->where('end_time','>=',time())
            ->first();
    }

}